package com.v1.util;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.MapUtils;
import org.apache.struts.util.LabelValueBean;

import com.v1.lo.BaseLO;
import com.v1.lo.Statement;
import com.v1.model.BaseElement;

public class Constant extends LifeCycle {
	public static final String USER = "user";

	@Resource(name = "BaseLO")
	private BaseLO lo;
	public Integer RECENT_DAYS;
	private Map<String, Object> map;
	public LabelValueBean TAG_COUNT;
	public String APPKEY;
	public String ADDRESS;

	public Integer getInteger(String key) {
		return MapUtils.getInteger(map, key);
	}

	public String getString(String key) {
		return MapUtils.getString(map, key);
	}

	@Override
	public void destroy() {
		map.clear();
	}

	@Override
	public void init() {
		map = lo.queryForMap(null, Statement.Scattered_getConstants, "id", "value");
		BaseElement.NOT_EXIST_THUMB = getString("not_exist_thumb");
		TAG_COUNT = new LabelValueBean(null, getString("tag_count"));
		RECENT_DAYS = getInteger("recent_days");
		APPKEY = getString("client_ID");
		ADDRESS = MapUtils.getString(map, "address", "http://betalife.cn/");
	}
}
